from datetime import datetime

from forward.extend.pydantic.base import BaseSchema
from forward.utils.tools import ToolsUtil


class MerchantSchema(BaseSchema):
    name: str | None = None
    address: str | None = None
    contact_name: str | None = None
    contact_phone: str | None = None
    status: int | None = None
    salesman_id: int | None = None
    model_config = {
        "alias_generator": ToolsUtil.to_lower_camel,
        "populate_by_name": True,
    }


class MerchantOutSchema(MerchantSchema):
    id: int | None = None
    created_time: datetime | None = None
    updated_time: datetime | None = None
    salesman_name: str | None = None
    model_config = {
        "alias_generator": ToolsUtil.to_lower_camel,
        "populate_by_name": True,
        "json_encoders": {datetime: lambda dt: dt.strftime("%Y-%m-%d %H:%M:%S")},
    }
